package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.AliPatModel;
import com.sanjiahantang.ythshopping.model.OrderSubmitMsg;
import com.sanjiahantang.ythshopping.model.SubmitOrder;
import com.sanjiahantang.ythshopping.model.WXpayModel;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.PayActiveView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/6/19.
 */

public class PayActivePresenter extends BasePresenter {

    PayActiveView payactivity;
    Context context ;
    SubmitOrder.sunorder pay;
    Map<String,String> params=new HashMap<>();
    OrderSubmitMsg.data data;

    public PayActivePresenter( PayActiveView payactivity,Context context ,SubmitOrder.sunorder pay)
    {

        this.payactivity=payactivity;
        this.context=context;
        this.pay=pay;
        params.put("key", ConfigValue.DATA_KEY);
        params.put("log_id",pay.getLog_id()+"");
        params.put("order_amount",pay.getOrder_amount());
        params.put("pay_id",pay.getPay_id());
        params.put("pay_set",pay.getPay_set());

    }

    public PayActivePresenter(PayActiveView payactivity, Context context ,String log_id, String orderAmount, String pay_id)
    {
        this.payactivity = payactivity;
        this.context = context;
        params.put("key", ConfigValue.DATA_KEY);
        params.put("log_id",log_id);
        params.put("order_amount",orderAmount);
        params.put("pay_id",pay_id);
        //params.put("pay_set",overset);

    }
    public PayActivePresenter( PayActiveView payactivity,Context context ,OrderSubmitMsg.data data,String sid)
    {

        this.payactivity=payactivity;
        this.context=context;
        this.data=data;
        params.put("key", ConfigValue.DATA_KEY);
        params.put("log_id",data.getLog_id()+"");
        params.put("order_amount",data.getOrder_amount());
        params.put("pay_id",data.getPay_id()+"");
        params.put("sid",sid);
       // params.put("pay_set",overset);

    }

    public void LoadWXPay()
    {
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "order/payAction", params, new BaseDelegate.ResultCallback<WXpayModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {

                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(WXpayModel response, Object tag) {
                payactivity.getWXinfo(response);
            }
        });
    }

    public void LoadsqAliPay()
    {
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "scan/payAction", params, new BaseDelegate.ResultCallback<AliPatModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(AliPatModel response, Object tag) {
                payactivity.getALiinfo(response);

            }
        });
    }


    public void LoadAliPay()
    {
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "order/payAction", params, new BaseDelegate.ResultCallback<AliPatModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(AliPatModel response, Object tag) {
                payactivity.getALiinfo(response);

            }
        });
    }

    public void LoadSQWXPay()
    {
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "scan/payAction", params, new BaseDelegate.ResultCallback<WXpayModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(WXpayModel response, Object tag) {
                payactivity.getWXinfo(response);

            }
        });
    }


}
